
/*
 * Hlpay-Plus aggregate payment system. Copyright
 * (c) 2022-2023 Hlpay Team Copyright has the right of final interpretation.
 */

package com.hlkj.pay.controller.admin;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.provider.Aes256EncryptionProvider;
import com.hlkj.pay.common.CommonResultCode;
import com.hlkj.pay.controller.BaseController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author HlpayTeam
 * @date 2024/09/03 14:10
 */
@Tag(name = "加解密")
@Slf4j
@RestController
@RequiredArgsConstructor
public class AdminCryptController extends BaseController {

    private final Aes256EncryptionProvider aes256EncryptionProvider;

    @Operation(summary = "加密")
    @GetMapping("/v1/adminuser/encrypt")
    CommonResult<String> encryptString(@RequestParam String account) {
        try {
            String encryptString = aes256EncryptionProvider.encryptString(account);
            return CommonResult.success(encryptString);
        }
        catch (Exception e) {
            log.error("encryptString error:{}", e.getMessage(), e);
            return CommonResult.error(CommonResultCode.DATA_ENCRYPT_ERROR);
        }
    }

    @Operation(summary = "用户账号-解密")
    @GetMapping("/v1/adminuser/decrypt")
    CommonResult<String> decrypt(@RequestParam String account) {
        try {

            String encryptString = aes256EncryptionProvider.decrypt(account);
            return CommonResult.success(encryptString);
        }
        catch (Exception e) {
            log.error("encryptString error:{}", e.getMessage(), e);
            return CommonResult.error(CommonResultCode.DATA_DECRYPT_ERROR);
        }
    }
}
